package com.project.config;

import com.project.interceptor.CustomInterceptor;
import com.project.interceptor.ManagerInterceptor;
import com.project.interceptor.SendInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MVCConfig implements WebMvcConfigurer {

    @Autowired
    private CustomInterceptor customInterceptor;

    @Autowired
    private ManagerInterceptor managerInterceptor;

    @Autowired
    private SendInterceptor sendInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration customRe = registry.addInterceptor(customInterceptor);
        customRe.addPathPatterns("/custom/**");

        InterceptorRegistration managerRe = registry.addInterceptor(managerInterceptor);
        managerRe.addPathPatterns("/manager/**");

        InterceptorRegistration sendRe = registry.addInterceptor(sendInterceptor);
        sendRe.addPathPatterns("/send/**");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/productImage/**")
        .addResourceLocations("file:D:/JAVA web/shoping/productImage/");
    }
}
